//获取散点图的数据
import { ScatterChartList } from '@/services/ScatterChart';
import { useEffect, useState } from 'react';

type User = {
  用户名: string;
  用户ID: string;
  手机号码: number;
  年龄: string;
  消费金额: number;
  月份: number;
  购买渠道: string;
  购买产品: string;
  购买数量: number;
};

type Product = {
  品名: string;
  品牌: string;
  产品编号: string;
  产品规格: string;
  产品单价: number;
  月份: number;
  口味: string;
  生产日期: string;
  购买数量: number;
};

type ScatterChartData = [User[], Product[]];

const useScatterChart = (): ScatterChartData[] => {
  //获取散点图的数据
  const [scatterChart, setscatterChart] = useState<ScatterChartData[]>([]);
  useEffect(() => {
    const fetchData = async () => {
      try {
        const res = await ScatterChartList();
        if (res.success) {
          console.log('setscatterChartList:', res.data.ScatterChart);
          setscatterChart(res.data.ScatterChart);
        }
      } catch (error) {
        console.error('Error fetching setscatterChartList data:', error);
      }
    };

    fetchData();
  }, []);

  return scatterChart;
};

export default useScatterChart;
